﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

using SosData;
using SosForms;
using System.Data.SqlServerCe;

namespace UOCmaker
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            FormSplash SplashFrm = new FormSplash();
            SplashFrm.TopMost = true;
            SplashFrm.Show();
            SplashFrm.Refresh();

            try
            {
                try
                {                           
                    //SosBL.DataBL.context.Configuration.ProxyCreationEnabled = false;
                    using (var db = new sosContext())
                    {
                        if (!db.Users.Any())
                        {
                            Usuario us = new Usuario();
                            us.Name = "Administrador";
                            us.NickName = "Admin";
                            us.Password = SosBL.SosSecurity.CalculateMD5Hash("Admin");
                            db.Users.Add(us);

                            Usuario us1 = new Usuario();
                            us1.Name = "Laura Moreno";
                            us1.NickName = "lmoreno";
                            us1.Password = SosBL.SosSecurity.CalculateMD5Hash("123456");
                            db.Users.Add(us1);

                            Usuario us2 = new Usuario();
                            us2.Name = "Jaume Benavent";
                            us2.NickName = "jbenavent";
                            us2.Password = SosBL.SosSecurity.CalculateMD5Hash("123456");
                            db.Users.Add(us2);

                            Usuario us3 = new Usuario();
                            us3.Name = "Roman Camps";
                            us3.NickName = "rcamps";
                            us3.Password = SosBL.SosSecurity.CalculateMD5Hash("123456");
                            db.Users.Add(us3);

                            db.SaveChanges();
                        }
                    }
                }

                catch (Exception ex) { MessageBox.Show(ex.Message); }

                //Usuario us = SosBL.DataBL.context.Users.Where(u => u.Id == 1).First();
                Parameters.UserId = 1;

                FormLogin loginFrm = new FormLogin();
                SplashFrm.Close();
                loginFrm.ShowDialog();

                if (loginFrm.Autorizado())
                {
                    Application.Run(new FormMdi());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
